package com.sky.controller;

import com.sky.entity.User;
import com.sky.result.LimitQueryResult;
import com.sky.result.Result;
import com.sky.service.UserService;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiOperation;

import javax.annotation.Resource;

/**
 * 用户信息(User)表控制层
 *
 * @author lining
 * @since 2024-10-23 16:33:34
 */
@Api(tags = "用户信息")
@RestController
@RequestMapping("user")
public class UserController {
    /**
     * 服务对象
     */
    @Resource
    private UserService userService;
    
        
    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @ApiOperation(value = "通过主键查询单条数据")
    @RequestMapping(value = "/queryById", method = RequestMethod.GET)
    public @ResponseBody
    Result<User> queryById(@RequestParam @ApiParam(value = "主键") Long id) {
        return this.userService.queryById(id);
    }
    
    /**
     * 通过主键修改单条数据【非空字段】
     *
     * @param user 实体
     * @return 编辑结果
     */
    @ApiOperation(value = "通过主键修改单条数据【非空字段】")
    @RequestMapping(value = "/updateById", method = RequestMethod.POST)
    public @ResponseBody Result<User> updateById(@RequestBody @ApiParam(value = "数据实体") User user) {
        return this.userService.updateById(user);
    }
    
    /**
     * 通过主键修改单条数据【所有字段】
     *
     * @param user 实体
     * @return 编辑结果
     */
    @ApiOperation(value = "通过主键修改单条数据【所有字段】")
    @RequestMapping(value = "/updateAllById", method = RequestMethod.POST)
    public @ResponseBody Result<User> updateAllById(@RequestBody @ApiParam(value = "数据实体") User user) {
        return this.userService.updateAllById(user);
    }
    
    /**
     * 通过主键删除单条数据
     *
     * @param id 主键
     * @return 删除数量
     */
    @ApiOperation(value = "通过主键删除单条数据")
    @RequestMapping(value = "/deleteById", method = RequestMethod.GET)
    public @ResponseBody Result<Integer> deleteById(@RequestParam @ApiParam(value = "主键") Long id) {
        return this.userService.deleteById(id);
    }
    
    
    
    /**
     * 通过主键批量删除数据
     *
     * @param idList 主键list
     * @return 删除数量
     */
    @ApiOperation(value = "通过主键批量删除数据")
    @RequestMapping(value = "/deleteAllByIdList", method = RequestMethod.POST)
    public @ResponseBody Result<Integer> deleteAllByIdList(@RequestBody @ApiParam(value = "主键list") List<Long> idList) {
        return this.userService.deleteAllByIdList(idList);
    }
        
    /**
     * 精准查询
     *
     * @param user 实体对象
     * @return 查询结果
     */
    @ApiOperation(value = "精准查询")
    @RequestMapping(value = "/queryAll", method = RequestMethod.POST)
    public @ResponseBody Result<List<User>> queryAll(@RequestBody @ApiParam(value = "数据实体") User user) {
        return this.userService.queryAll(user);
    }
    
    /**
     * 模糊查询
     *
     * @param user 实体对象
     * @return 查询结果
     */
    @ApiOperation(value = "模糊查询")
    @RequestMapping(value = "/queryAllLike", method = RequestMethod.POST)
    public @ResponseBody Result<List<User>> queryAllLike(@RequestBody @ApiParam(value = "数据实体") User user) {
        return this.userService.queryAllLike(user);
    }
    
    /**
     * 精准分页查询
     *
     * @param user 实体对象
     * @return 查询结果
     */
    @ApiOperation(value = "精准分页查询")
    @RequestMapping(value = "/queryAllLimit", method = RequestMethod.POST)
    public @ResponseBody Result<LimitQueryResult<List<User>>> queryAllLimit(@RequestBody @ApiParam(value = "数据实体") User user, @RequestParam @ApiParam(value = "第几页") int pageNumber, @RequestParam @ApiParam(value = "每页数量") int pageSize) {
        return this.userService.queryAllLimit(user, pageSize, (pageNumber - 1) * pageSize);
    }
    
    /**
     * 模糊分页查询
     *
     * @param user 实体对象
     * @return 查询结果
     */
    @ApiOperation(value = "模糊分页查询")
    @RequestMapping(value = "/queryAllLikeLimit", method = RequestMethod.POST)
    public @ResponseBody Result<LimitQueryResult<List<User>>> queryAllLikeLimit(@RequestBody @ApiParam(value = "数据实体") User user, @RequestParam @ApiParam(value = "第几页") int pageNumber, @RequestParam @ApiParam(value = "每页数量") int pageSize) {
        return this.userService.queryAllLikeLimit(user, pageSize, (pageNumber - 1) * pageSize);
    }

    /**
     * 统计总行数
     *
     * @param user 实体对象
     * @return 查询结果
     */
    @ApiOperation(value = "统计总行数")
    @RequestMapping(value = "/count", method = RequestMethod.POST)
    public @ResponseBody Result<Long> count(@RequestBody @ApiParam(value = "数据实体") User user) {
        return this.userService.count(user);
    }

    /**
     * 统计总行数(模糊查询)
     *
     * @param user 实体对象
     * @return 查询结果
     */
    @ApiOperation(value = "统计总行数(模糊查询)")
    @RequestMapping(value = "/countLike", method = RequestMethod.POST)
    public @ResponseBody Result<Long> countLike(@RequestBody @ApiParam(value = "数据实体") User user) {
        return this.userService.countLike(user);
    }

    /**
     * 新增数据
     *
     * @param user 实体
     * @return 新增结果
     */
    @ApiOperation(value = "新增数据")
    @RequestMapping(value = "/insert", method = RequestMethod.POST)
    public @ResponseBody Result<User> insert(@RequestBody @ApiParam(value = "数据实体") User user) {
        return this.userService.insert(user);
    }
    
    /**
     * 批量新增数据
     *
     * @param entities List<User> 实例对象列表
     * @return 影响行数
     */
    @ApiOperation(value = "批量新增数据")
    @RequestMapping(value = "/insertBatch", method = RequestMethod.POST)
    public @ResponseBody Result<Integer> insertBatch(@RequestBody @ApiParam(value = "实例对象列表") List<User> entities) {
        return this.userService.insertBatch(entities);
    }
    
    /**
     * 通过实体精准删除数据
     *
     * @param user 实体对象
     * @return 影响行数
     */
    @ApiOperation(value = "通过实体精准删除数据")
    @RequestMapping(value = "/deleteAll", method = RequestMethod.POST)
    public @ResponseBody Result<Integer> deleteAll(@RequestBody @ApiParam(value = "数据实体") User user) {
        return this.userService.deleteAll(user);
    }

}

